// 取出Cookie
export const getCookie = (name) => {
  const arrCookie = document.cookie.split("; ");
  for (let i = 0; i < arrCookie.length; i++) {
    let arr = arrCookie[i].split("=");
    if (name === arr[0]) {
      return arr[1];
    }
  }
  return "";
};

// 设置Cookie
export const setCookie = (name, value, day) => {
  // 当设置的时间等于0时，不设置expires属性，cookie在浏览器关闭后删除
  if (day !== 0) {
    const expires = day * 24 * 60 * 60 * 1000;
    const date = new Date(+new Date() + expires);
    document.cookie = `${name}=${escape(value)};expires=${date.toUTCString()};path=/`;
  } else {
    document.cookie = `${name}=${escape(value)};path=/`;
  }
};